﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BootyBay.Models;

namespace BootyBay.Repository
{
    public class ApplicationInfoRepository
    {
        //create singlton instance
        static ApplicationInfoRepository<ApplicationInfo> _instance = new ApplicationInfoRepository<ApplicationInfo>();
        public static ApplicationInfoRepository<ApplicationInfo> Instance()
        {
            return _instance;
        }
    }

    public class ApplicationInfoRepository<T> : RepositoryBase<T> where T : ApplicationInfo
    {
        public ApplicationVersionInfo GetVersionInfoByAppVersionId(int applicationVersionInfoId)
        {
            return GetAll().SelectMany(a => a.ApplicationVersionInfoes.Where(m => m.Id == applicationVersionInfoId)).FirstOrDefault();
        }
    }

    public class ApplicationVersionInfoRepository
    {
        //create singlton instance
        static ApplicationVersionInfoRepository<ApplicationVersionInfo> _instance = new ApplicationVersionInfoRepository<ApplicationVersionInfo>();
        public static ApplicationVersionInfoRepository<ApplicationVersionInfo> Instance()
        {
            return _instance;
        }
    }

    public class ApplicationVersionInfoRepository<T> : RepositoryBase<T> where T : ApplicationVersionInfo
    {
    }

    public class ApplicationPublicRepository
    {
        //create singlton instance
        static ApplicationPublicRepository<ApplicationPublic> _instance = new ApplicationPublicRepository<ApplicationPublic>();
        public static ApplicationPublicRepository<ApplicationPublic> Instance()
        {
            return _instance;
        }
    }

    public class ApplicationPublicRepository<T> : RepositoryBase<T> where T : ApplicationPublic
    {
    }

    public class AppArchitectureRepository
    {
        //create singlton instance
        static AppArchitectureRepository<ApplicationProcessorArchitecture> _instance = new AppArchitectureRepository<ApplicationProcessorArchitecture>();
        public static AppArchitectureRepository<ApplicationProcessorArchitecture> Instance()
        {
            return _instance;
        }
    }

    public class AppArchitectureRepository<T> : RepositoryBase<T> where T : ApplicationProcessorArchitecture
    {
        public IQueryable<ApplicationProcessorArchitecture> GetByVersionId(int applicationVersionInfoId)
        {
            return GetAll().Where(p => p.Id_ApplicationVersionInfo == applicationVersionInfoId);

        }

        public ApplicationProcessorArchitecture GetPackageByArchitecture(int versionId, int processorArchitecture)
        {
            return GetAll().Where(p => p.Id_ApplicationVersionInfo == versionId
                && (p.ProcessorArchitecture == (int)ProcessorArchitecture.Neutual || p.ProcessorArchitecture == processorArchitecture))
                .FirstOrDefault();
        }
    }
}
